$(function(){
	$('.engineer_L_item').height(screen.availHeight-200+"px")
	$(".engineer_R_info_map").height(screen.availHeight-240+"px")
	$('.engineer_L_item').find("li:first").addClass("engineer_bk");
	$('.engineerTable').dataTable(pageSetting(baseURL));
	var engineerIndex_1=layer.load("正在加载数据，请稍候！");
	$.ajaxSetup({
		type:"get",
		datatype:"json",
		success:function(result){
			layer.close(engineerIndex_1);
			if(result.flag){
				$.each(result.results,function(i,n){

					if(n.name!="" && n.name!=null){
						addsProvince.push([n.name,n.engineerTotal,n.projectTotal]);
						$(".engineer_R_info_search_s").find("select").append("<option value='"+n.code+"'>"+n.name+"</option>")
					}
					if(n.cityDatas.length!=0){
						$.each(n.cityDatas,function(a,b){
							addscity.push([b.name,b.engineerTotal,b.projectTotal,n.name])
						})
					}
				})
				bdGEO();
			}else layer.msg(result.message)
		},
		error:function(result){
			layer.msg(result.errorMessage)
		}
	})
	$.ajax({
		url:baseURL+"/api/index/getChinaAllEngineerData?t="+new Date().getTime()
	})
	$('.engineer_L_item').find("li").on('click',function(e){
		e.stopPropagation();
		$(e.currentTarget).addClass("engineer_bk").siblings().removeClass("engineer_bk");
		if($(e.currentTarget).attr("data-num")=="1"){
			window.location.href=baseURL+"/api/index/showEngineerPos?t="+new Date().getTime();
		}else {
			window.location.href=baseURL+"/api/index/showMonthlyDatasChart?page=2&t="+new Date().getTime();
		}
	})
	$(".engineer_R_info_search_b").on('click',function(){
		window.location.href=baseURL+"/api/index/showMonthlyDatasChart?page=1&t="+new Date().getTime();
	})
})
doSearch = function(){
	if(!isPrivinceFlag || !isCityFlag){
		layer.msg("数据正在加载中，请稍后操作")
		return;
	}
	if($("#engineerSelect").find("option:selected").html()=="全国"){
		$("#provinceWord").html("省份");
		numProvince = 0;
		map.setZoom(5);
		map.clearOverlays();
		bdGEO();
		$('.engineerTable').DataTable().draw();
		//$('.engineerTable').DataTable().search(seachValue).draw();
		
	}else {
		$("#provinceWord").html("城市");
		var seachValue={};
		$('.engineerTable').DataTable().search(seachValue).draw();
		getBoundary($("#engineerSelect").find("option:selected").html());	
	}
	
}	
//从服务器分批取数据
pageSetting =  function(){
		var optsortable = {
					"bPaginate":true,
					"bProcessing":true,
					"stateSave":true,
					"bLengthChange":false,
					"iDisplayLength":10,
					"sAjaxSource":baseURL+"/api/index/getProvinceDataList?t="+new Date().getTime(),
					"sPaginationType":'simple_numbers',
					"bServerSide": true,
					"bSort": false,             
					"bFilter": false,  
					"bInfo":false,
					"aoColumnDefs" : [] ,
					"fnServerData": function(sSource, aoData, fnCallback){
							var globalSearch = {};
							var searchConditions = {};
							if($.trim($(".engineer_R_info_search_s").find("select").val())=='全国'){
								sSource=baseURL+"/api/index/getProvinceDataList?t="+new Date().getTime();
							}else sSource=baseURL+"/api/index/getCityDataList?t="+new Date().getTime();
							searchConditions.provinceCode=$.trim($(".engineer_R_info_search_s").find("select").val());
							globalSearch.name= 'globalSearch';
							globalSearch.value= JSON.stringify(searchConditions);
							aoData.push(globalSearch);
							$.ajax({
								url : sSource,
								data : aoData,
								timeout : 30000,
								contentType : "application/json; charset=utf-8",
								success : function(result) {
									if(!result.flag){
					            		if(result.statusCode==503){
					            		  location=baseURL+"/api/tologin";
					            		}else{
					            		  layer.msg("查询失败！");
					            		}
					            	  return;
					            	}
									
									if(result.flag){
							        	var obj =result;
							        	var data = obj.results;	
										var aaData = [];
										var dataResult = {};
										dataResult.iTotalRecords = obj.totalcount;
										dataResult.iTotalDisplayRecords= obj.totalcount;
										dataResult.iDisplayStart = obj.offset;
										dataResult.iDisplayLength= obj.limit;
										dataResult.aaData = aaData;
										//json重构数组对象 
										$.each(data,function(i,val){
											aaData[i]=[];
											aaData[i].push(val.name==null?'/':val.name);
											aaData[i].push(val.engineerTotal==null?'/':val.engineerTotal);
											aaData[i].push(val.projectTotal==null?'/':val.projectTotal);
										});
							            fnCallback(dataResult);   
						          }
								  }    
						     });
							
					}
				}	
		$("#DataTables_Table_0_previous,#DataTables_Table_0_next").hide();
		return optsortable;
}